package cn.edu.xmu.restfuldemo.dao;

import cn.edu.xmu.restfuldemo.mapper.OrdersPoMapper;
import cn.edu.xmu.restfuldemo.mapper.OrdersPoMapper1;
import cn.edu.xmu.restfuldemo.model.BO.Orders;
import cn.edu.xmu.restfuldemo.model.PO.OrdersPo;
import cn.edu.xmu.restfuldemo.model.VO.OrdersRetVo;
import cn.edu.xmu.restfuldemo.model.VO.OrdersVo;
import cn.edu.xmu.restfuldemo.util.ResponseCode;
import cn.edu.xmu.restfuldemo.util.ReturnObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @author RenJieZheng
 */
@Repository
public class OrdersDao {
    @Autowired
    OrdersPoMapper ordersPoMapper;

    @Autowired
    OrdersPoMapper1 ordersPoMapper1;


    /**
     * 根据id查找orders
     * @param id id
     * @return orders
     */
    public ReturnObject<Orders> findOrdersById(Long id){
        OrdersPo ordersPo = ordersPoMapper.selectByPrimaryKey(id);
        OrdersVo ordersVo = new OrdersVo(ordersPo);
        return new ReturnObject<>(ordersVo.newOrders());
    }

    /**
     * 插入orders
     * @param orders orders
     * @return returnObject
     */
    public ReturnObject<Long> addOrder(Orders orders){
        OrdersPo ordersPo = orders.newOrdersPo();
        ordersPoMapper.insert(ordersPo);
        return new ReturnObject<Long>(ordersPo.getId());
    }

    public ReturnObject<OrdersRetVo> findOrdersByOrdersId(Long id){
        OrdersRetVo ordersRetVo = ordersPoMapper1.selectByOrderId(id);
        return new ReturnObject<>(ordersRetVo);
    }
}
